package com.atguigu04.set.ex1;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

public class test {
    public static void main(String[] args) {
        ArrayList arrayList=new ArrayList();
        arrayList.add(22);
        arrayList.add(22);
        arrayList.add(22);
        arrayList.add(26);
        arrayList.add(26);
        arrayList.add(26);
        arrayList.add(45);
        arrayList.add(45);
        arrayList.add(45);
        arrayList.add(66);
        List list=duplicateList(arrayList);
        Iterator iterator=list.iterator();
        for (Object o:list
             ) {
            System.out.println(o);
        }

        System.out.println(list);

    }
    public static List duplicateList(List list){
        List result=new ArrayList();
        Iterator it= list.iterator();

        HashSet set=new HashSet();
        while(it.hasNext()){
            set.add(it.next());
        }
        Iterator it1= set.iterator();
        while(it1.hasNext()){
            result.add(it1.next());
        }
        return result;

        //方式2:
//        HashSet set1 = new HashSet(list);
//        List list1 = new ArrayList(set1);
//        return list1;

    }
}
